// Created by wangliang on 2025/2/14.
import 'package:flutter_app_demo/utils/toast.dart';
import 'package:mvvm_plus/mvvm_plus.dart';

abstract class BaseViewModel extends ViewModel {
  bool _isDisposed = false;

  @override
  void initState() {
    _isDisposed = false;
    super.initState();
  }

  void safeBuildView() {
    if (!_isDisposed) {
      buildView();
    } else {
      // call buildView after disposed, so ignore.
    }
  }

  showToast(String message) {
    ToastUtil.showToast(context, message);
  }

  @override
  void dispose() {
    _isDisposed = true;
    super.dispose();
  }
}
